#pragma once

#include "Image.h"


namespace uml {

const QString Image::content_default_ = "";
const QString Image::format_default_ = "";
const QString Image::location_default_ = "";
Image::Image(const QString& umlType)
    : Element(umlType) {}

void Image::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Element::fromJson(json, errorList);
    content_ = json.value("content").toString(content_default_);
    format_ = json.value("format").toString(format_default_);
    location_ = json.value("location").toString(location_default_);
}

void Image::toJson(QJsonObject& json) {
    Element::toJson(json);
    if (content_ != content_default_) {
        json.insert("content", content_);
    }
    if (format_ != format_default_) {
        json.insert("format", format_);
    }
    if (location_ != location_default_) {
        json.insert("location", location_);
    }
}

/// <summary>
/// content getter
/// This contains the serialization of the image according to the format. The value
/// could represent a bitmap, image such as a GIF file, or drawing 'instructions'
/// using a standard such as Scalable Vector Graphic (SVG) (which is XML based).
/// </summary>
QString Image::content() const {
    return content_;
}

/// <summary>
/// content setter
/// This contains the serialization of the image according to the format. The value
/// could represent a bitmap, image such as a GIF file, or drawing 'instructions'
/// using a standard such as Scalable Vector Graphic (SVG) (which is XML based).
/// </summary>
void Image::setContent(const QString& value) {
    content_ = value;
}

/// <summary>
/// format getter
/// This indicates the format of the content, which is how the string content should
/// be interpreted. The following values are reserved: SVG, GIF, PNG, JPG, WMF, EMF,
/// BMP. In addition the prefix 'MIME: ' is also reserved. This option can be used
/// as an alternative to express the reserved values above, for example "SVG" could
/// instead be expressed as "MIME: image/svg+xml".
/// </summary>
QString Image::format() const {
    return format_;
}

/// <summary>
/// format setter
/// This indicates the format of the content, which is how the string content should
/// be interpreted. The following values are reserved: SVG, GIF, PNG, JPG, WMF, EMF,
/// BMP. In addition the prefix 'MIME: ' is also reserved. This option can be used
/// as an alternative to express the reserved values above, for example "SVG" could
/// instead be expressed as "MIME: image/svg+xml".
/// </summary>
void Image::setFormat(const QString& value) {
    format_ = value;
}

/// <summary>
/// location getter
/// This contains a location that can be used by a tool to locate the image as an
/// alternative to embedding it in the stereotype.
/// </summary>
QString Image::location() const {
    return location_;
}

/// <summary>
/// location setter
/// This contains a location that can be used by a tool to locate the image as an
/// alternative to embedding it in the stereotype.
/// </summary>
void Image::setLocation(const QString& value) {
    location_ = value;
}

} // namespace uml
